<?php

namespace App\Models;

use App\Enums\MiniAPP\DuelStatus;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Duel extends Model
{
    use HasFactory, SoftDeletes;

    protected $fillable = [
        'member_id',
        'opponent_id',
        'member_wechat',
        'start_at',
        'fake_table_type_id',
        'duel_type_id',
        'duel_level_id',
        'remark',
        'store_id',
        'status',
    ];

    protected $casts = [
        'status' => DuelStatus::class,
    ];

    public function member()
    {
        return $this->belongsTo(Member::class);
    }

    public function opponent()
    {
        return $this->belongsTo(Member::class, 'opponent_id');
    }

    public function tableType()
    {
        return $this->belongsTo(FakeTableType::class, 'fake_table_type_id');
    }

    public function duelType()
    {
        return $this->belongsTo(DuelType::class, 'duel_type_id');
    }

    public function duelLevel()
    {
        return $this->belongsTo(DuelLevel::class, 'duel_level_id');
    }

    public function store()
    {
        return $this->belongsTo(Store::class);
    }
}
